#include <iostream>
#include <stdio.h>

#include <iostream>
#include <memory>
#include <vector>
#include <unordered_set>

class Solution {
public:
    std::vector<int> intersection(std::vector<int>& nums1, std::vector<int>& nums2) {
        std::unordered_set<int> result_set; // 存放结果
        std::unordered_set<int> nums_set(nums1.begin(), nums1.end());
        for (int num : nums2) {
            // 发现nums2的元素 在nums_set里又出现过
            if (nums_set.find(num) != nums_set.end()) {
                result_set.insert(num);
            }
        }
        return std::vector<int>(result_set.begin(), result_set.end());
    }
};


int main(int argv, char**argc)
{
    std::vector<int> vec1{1,2,2,1};
    std::vector<int> vec2{2,2};
    std::vector<int> ret;

    Solution solver;
    ret = solver.intersection(vec1, vec2);

    for( auto num:ret){
        printf("%d ,", num);
    }
    printf("\n");


    return 0;
}
